<%= partial :searchform %>

<div id="content">
<h4>Result counts over the past <%= @readable_timeperiod %> <%= @readable_timeunit %> for '<%=h params[:q] %>'</h4>
<div id="visual" style="width:850px;height:200px;"></div>

<hr style="margin: 2em; width: 70%">

<h4>Results <%= params[:offset] %> - <%= [@hits,params[:offset] + params[:limit]].min %> of <%= @hits %> for <%=h params[:q] %></h4>
<% if params[:offset] > 0 %>
  <%= link_to "first", url(:controller => "search", :action => "query",
                            :q => params[:q],
                            :offset => 0,
                            :limit => params[:limit],
                            :log_type => params[:log_type]) %> |
  <%= link_to "prev", url(:controller => "search", :action => "query",
                          :q => params[:q],
                          :offset => [0, params[:offset] - params[:limit]].max,
                          :limit => params[:limit],
                          :log_type => params[:log_type]) %>
<% end %>
<%= "|" if @hits > params[:limit] %>
<% if params[:offset] + params[:limit] < @hits %>
  <%= link_to "next", url(:controller => "search", :action => "query",
                          :q => params[:q],
                          :offset => [@hits - params[:limit], params[:offset] + params[:limit]].min,
                          :limit => params[:limit],
                          :log_type => params[:log_type]) %>
                          |
  <%= link_to "last", url(:controller => "search", :action => "query",
                          :q => params[:q],
                          :offset => @hits - params[:limit],
                          :limit => params[:limit],
                          :log_type => params[:log_type]) %>
<% end %>

<pre>
<% @results.each do |result| -%>
 (<span class="datestamp"><%=h Time.at(result["_source"]["@DATE"]).strftime("%Y/%m/%d %H:%M:%S") %></span>) <%=h result["_source"]["@LINE"] %>
<% end -%>
</pre>

<script id="source">
$(function () {
  var graphdata = <%= @graphdata.to_json %>;

  var plot = $.plot($("#visual"), 
         [
           { data: graphdata,
             bars: {
               show: true,
               barWidth: <%= (params[:graphstep] or 60 * 60).to_i * 1000 %>,
             }
           }
         ], 
         { xaxis: { mode: "time" } }
        );

  var nowpoint = plot.pointOffset( { x: <%= (Time.now.to_i + Time.now.gmtoff) * 1000 %>, y: 1 } );
  var note = $("<div>").css("position", "absolute")
    .css("left", nowpoint.left)
    .css("top", "10px")
    .css("height", "170px")
    .css("border-left", "1px dashed grey")
    //.css("border-bottom", "1px solid grey")
    //.css("border-top", "1px solid grey")
    //.css("text-align", "center")
    //.css("margin-left", ".5em")
    //.css("font-weight", "bold")
    //.css("text-align", "top")
    //.css("white-space", "nowrap")
    //.css("-webkit-transform", "rotate(90deg)")
    //.css("-webkit-transform-origin", "0 0")
    //.css("-moz-transform", "rotate(90deg)")
    //.css("-moz-transform-origin", "0 0")
    //.html("<%= Time.now.strftime("%b, %d %Y %H:%M:%S") %>");
  $("#visual").append(note) 
  //var ctx = plot.getCanvas().getContext("2d");
  //ctx.moveTo(nowpoint.left, 0);
  //console.log(plot)
  //ctx.lineTo(nowpoint.left, nowpoint.top);
  //ctx.strokeStyle = "#88FF00";
  //ctx.stroke();
}); 
</script>
</div>
